package com.k.kpp.web.easyexcel2.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.k.kc.common.resp.Result;
import com.k.kpp.web.easyexcel2.domain.ExcelTypeEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.io.InputStream;

@RestController
@ApiSupport(author = "ljw", order = 31)
@Api(tags = "Excel")
@Validated
@RequestMapping(value = "/excel/import")
public class ImportController {
//    @Autowired
//    private Map<String, IExcelService> excelServiceMap;

    @ApiOperation(value = "数据导入 -  必达点")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "excelType", required = true, dataType = "string", value = "必到点模板填固定值:arrivePoint_excel", example = "arrivePoint_excel"),
            @ApiImplicitParam(paramType = "file", name = "file", required = true, dataType = "MultipartFile", value = "文件")})
    @ApiOperationSupport(order = 10)
    @RequestMapping(value = "/arrivePoint", method = RequestMethod.POST)
    public Result<String> importData(@RequestParam(value = "file") MultipartFile file,
                                     @RequestParam(value = "excelType") String excelType) throws IOException {
        // String fileName = "e:\\test\\arrive1_exp_data6.xlsx";
        // 这里默认每次会读取100条数据 然后返回过来 直接调用使用数据就行
        // 具体需要返回多少行可以在`PageReadListener`的构造函数设置
        InputStream is = file.getInputStream();
        //ExcelTypeEnum.matchOpValue(excelType).ifPresent(a -> excelServiceMap.get(a.getValue()).importData(is));
        return Result.success();
    }
}
